package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.SysRole;
import com.easy.common.service.IPermissionService;
import com.easy.common.service.IRoleService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("role")
public class RoleController {
    @Autowired
    IRoleService roleService;
    @PostMapping("/")
    public ResultData insert(@RequestBody SysRole role){
        SysRole data=roleService.insert(role);
        return ResultData.success(data);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody SysRole role){
        SysRole data=roleService.update(role);
        return ResultData.success(data);
    }
    @DeleteMapping("/id")
    public ResultData delete(@PathVariable Integer id){
        int result=roleService.delete(id);
        if (result>=1){
            return ResultData.success();
        }else {
            return ResultData.fail();
        }
    }
    @GetMapping("/id")
    public ResultData getByID(@PathVariable Integer id){
        SysRole role=roleService.getById(id);
        return ResultData.success(role);
    }
    @GetMapping("/page")
    public ResultData getListByPage(Page page,@RequestBody SysRole role){
        IPage<SysRole> data=roleService.getListByPage(page,role);
        return ResultData.success(data);
    }
    @GetMapping("/list")
    public ResultData getList(SysRole role){
        List<SysRole> data=roleService.getList(role);
        return ResultData.success(data);
    }


}
